// 在install里面添加要用的组件
function install (Vue) {
  Vue.filter('datetimeFormat', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('yyyy-MM-dd hh:mm:ss')
  })

  Vue.filter('datetimeShortFormat1', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('yyyy-MM-dd hh:mm')
  })

  Vue.filter('datetimeShortFormat2', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('MM-dd hh:mm')
  })

  Vue.filter('dateFormat', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('yyyy-MM-dd')
  })

  Vue.filter('dateShortFormat', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('MM-dd')
  })

  Vue.filter('timeFormat', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('hh:mm:ss')
  })

  Vue.filter('timeShortFormat', function (v) {
    if (v === null || v === undefined) {
      return ''
    }
    const date = v instanceof Date ? v : new Date(v)
    return date.format('hh:mm')
  })
}

export default {
  install
}
